package logic

import (
	"context"
	"shopexam/model/mysql"

	"shopexam/shoprpc/internal/svc"
	"shopexam/shoprpc/shoprpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopAddLogic) ShopAdd(in *shoprpc.ShopAddRequest) (*shoprpc.ShopAddResponse, error) {
	// todo: add your logic here and delete this line
	products := mysql.Products{
		Nums:     in.Nums,
		Name:     in.Name,
		Price:    float64(in.Price),
		OldPrice: float64(in.OldPrice),
		Image:    in.Image,
		Intro:    in.Intro,
		UserId:   int(in.UserId),
	}
	mysql.DB.Debug().Create(&products)
	return &shoprpc.ShopAddResponse{Id: int64(products.ID)}, nil
}
